package com.util;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Vector;
import java.util.HashMap;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.lang.reflect.Method;

/**
 * Created by IntelliJ IDEA.
 * User: zhuyoulong
 * Date: 2006-10-30
 * Time: 13:52:10
 * To change this template use File | Settings | File Templates.
 */
public final class Function implements Serializable {

    public Function() {
    }

    public static void AlertBackNoClose(String message, int history, HttpServletRequest request, HttpServletResponse response,String name) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.history.go(" + history + ");\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    
    public static void AlertNoClose(String message, int history, HttpServletRequest request, HttpServletResponse response,String name) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    
    public static void AlertAndCloseRealy(String message, int history, HttpServletRequest request, HttpServletResponse response,String name) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
//            buffer.append("window.history.go(" + history + ");\n");
            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    
    public static void AlertAndClose(String message, int history, HttpServletRequest request, HttpServletResponse response,String name) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.history.go(" + history + ");\n");
            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    public static void AlertAndGoUrl(String message, String url, HttpServletRequest request, HttpServletResponse response,String name) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + name + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.location=(" + url + ");\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    public static void commonAlertAndBack(String message, int history, HttpServletRequest request, HttpServletResponse response,String name) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.history.go(" + history + ");\n");
//            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    
    /**
     * 
     * <p>功能描述：发送消息后，close page,并给父页面赋值</p>
     * @param message 要发送的消息
     * @param history 历史
     * @param request
     * @param response
     * @param name
     * @author:朱有龙
     * @update: [日期YYYY-MM-DD][更改人姓名] [变更描述]
     */
    public static void addFinishManAlert(String message, int history, HttpServletRequest request, HttpServletResponse response,String name) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.opener.form1.finishman.value='"+name+"';\n");            
            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    /**
     * 
     * <p>功能描述：项目完成人脚本提示</p>
     * @param message
     * @param history
     * @param request
     * @param response
     * @param name
     * @author:朱有龙
     * @update: [日期YYYY-MM-DD][更改人姓名] [变更描述]
     */
    public static void addFinishUnitAlert(String message, int history, HttpServletRequest request, HttpServletResponse response,String name) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.opener.document.getElementById('finishunit').value='"+name+"';\n");            
            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    /**
     * Js导航<br>
     * 当前url换成新的url
     * @param strUrl
     * @param response
     */
    public static void navigate(String strUrl, HttpServletResponse response) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            PrintWriter out = response.getWriter();
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            buffer.append("<title> New Document</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.location.replace('" + strUrl + "');\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }

    /**
     * Js导航<br>
     * 到历史记录
     * @param history
     * @param response
     */
    public static void navigate(int history, HttpServletResponse response) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            PrintWriter out = response.getWriter();
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            buffer.append("<title> New Document</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.history.go(" + history + ");\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }

    /**
     * Js导航<br>
     * 退回登录页面
     * @deprecated
     * @param message 要发送的消息
     * @param request
     * @param response
     */
    public static void navigate(String message, HttpServletRequest request, HttpServletResponse response) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("top.location.replace('/login/login.jsp');\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }

    /**
     * 发送消息后，转到历史
     * @param message 要发送的消息
     * @param history 历史
     * @param request
     * @param response
     */
    public static void navigate(String message, int history, HttpServletRequest request, HttpServletResponse response,String charset) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            if(charset !=null){
                response.setContentType("text/html;charset="+charset+"");
            }
            else{
                response.setContentType("text/html");
            }
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.history.go(" + history + ");\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    /**
     * 发送消息后，close page
     * @param message 要发送的消息
     * @param history 历史
     * @param request
     * @param response
     */
    public static void alertClose2(String message, int history, HttpServletRequest request, HttpServletResponse response) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    public static void alertClose22(String message, int history, HttpServletRequest request, HttpServletResponse response) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.opener.close();\n");
            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    /**
     * 发送消息后，close page
     * @param message 要发送的消息
     * @param request
     * @param response
     */
    public static void alertClose3(String message, HttpServletRequest request, HttpServletResponse response,String charset) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=ISO8859_1");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.opener.location.reload();\n");
            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
    /**
     * 发送消息后，close page
     * @param message 要发送的消息
     * @param request
     * @param response
     */
    public static void alertAndBack(String message, int history,HttpServletRequest request, HttpServletResponse response,String charset) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=utf-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.history.go(" + history + ");\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }

    public static void alertsingle(String message,HttpServletRequest request, HttpServletResponse response) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html;charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }
      /**
     * Js导航<br>
     * 发送消息后转到url
     * @param message 要发送的消息
     * @param url 要转的url
     * @param request
     * @param response
     */
    public static void navigate(String message, String url, HttpServletRequest request, HttpServletResponse response) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.location.replace('" + url + "');\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }

    /**
     * Js导航<br>
     * 发送消息后转到url
     * @param message 要发送的消息
     * @param url 要转的url
     * @param request
     * @param response
     */
    public static void navigateAndRC(String message, String url, HttpServletRequest request, HttpServletResponse response) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.location.replace('" + url + "');\n");
            buffer.append("window.opener.location.reload();\n");
            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            buffer=null;
        }
    }

    /**
     * 发出消息后，关闭窗口
     * @param message 要发送的消息
     * @param response
     */
    public static void alertClose(String message, HttpServletResponse response) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\n");
            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(buffer.toString());
        } catch (Exception exception) {
        } finally{
            buffer=null;
        }
    }

    /**
     * 发送消息后，把开启的窗口刷新后，关闭本窗口
     * @param message 要发送的消息
     * @param response
     */
    public static void alertOpenerReloadClose(String message, HttpServletResponse response) {
        StringBuffer buffer = new StringBuffer(1024);
        try {
            response.setContentType("text/html");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            buffer.append("<html>\n");
            buffer.append("<head>\n");
            buffer.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            buffer.append("<title>" + message + "</title>\n");
            buffer.append("</head>\n");
            buffer.append("<script language='JavaScript'>\n");
            buffer.append("window.alert('" + message + "');\ntry{window.opener.location.reload();}catch(e){}\n");
            buffer.append("window.close();\n");
            buffer.append("</script>\n");
            buffer.append("<body>\n");
            buffer.append("</body>\n");
            buffer.append("</html>\n");
            PrintWriter out = null;
            out = response.getWriter();
            out.print(buffer.toString());
        } catch (Exception exception) {
        } finally{
            buffer=null;
        }
    }

    /**
     * Js导航<br>
     * 发送消息后目标帧转到指定url
     * @param message 要发送的消息
     * @param targetFrame 目标帧
     * @param url 要转的url
     * @param request
     * @param response
     */
    public static void navigate(String message, String targetFrame, String url, HttpServletRequest request, HttpServletResponse response) {
        StringBuffer sb = new StringBuffer(1024);
        try {
            response.setContentType("text/html");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            sb.append("<html>\n");
            sb.append("<head>\n");
            sb.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            sb.append("<title>" + message + "</title>\n");
            sb.append("</head>\n");
            sb.append("<script language='JavaScript'>\n");
            sb.append("window.alert('" + message + "');\n");
            sb.append(targetFrame + ".location ='" + url + "';\n");
            sb.append("</script>\n");
            sb.append("<body>\n");
            sb.append("</body>\n");
            sb.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(sb.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            sb=null;
        }
    }

        /**
     * Js导航<br>
     * 发送消息后目标帧转到指定url
     * @param message 要发送的消息
     * @param request
     * @param response
     */
    public static void navigateWithCode(String message, String code,HttpServletRequest request, HttpServletResponse response) {
        StringBuffer sb = new StringBuffer(1024);
        try {
            response.setContentType("text/html");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0L);
            sb.append("<html>\n");
            sb.append("<head>\n");
            sb.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
            sb.append("<title>" + message + "</title>\n");
            sb.append("</head>\n");
            sb.append("<script language='JavaScript'>\n");
            sb.append("window.alert('" + message + "');\n");
            sb.append(code + "\n");
            sb.append("</script>\n");
            sb.append("<body>\n");
            sb.append("</body>\n");
            sb.append("</html>\n");
            PrintWriter out = response.getWriter();
            out.print(sb.toString());
            out.close();
        } catch (IOException e) {
            e.printStackTrace(System.out);
        } finally{
            sb=null;
        }
    }

    /**
     * 产生一个32位长的guid
     * @return
     */
    public static String getGuid() {
        return getGuid(32);
    }

    /**
     * 产生一个指定的guid
     * @param len
     * @return
     */
    public static String getGuid(int len) {
        StringBuffer sb = new StringBuffer(len);
        for (int i = 0; i < len; i++) {
            int k;
            switch ((int) (Math.random() * 2D)) {
                case 0: // '\0'
                    k = (int) (Math.random() * 10D) + 48;
                    break;

                case 1: // '\001'
                    k = (int) (Math.random() * 26D) + 65;
                    break;

                default:
                    k = 95;
                    break;
            }
            sb.append((char) k);
        }
        String result=sb.toString();                           //modify by zhulin 20040826
        sb=null;
        return result;
    }

    /**
     * JavaScript 发出消息
     * @param str
     * @return
     */
    public static String alert(String str) {
        StringBuffer sb = new StringBuffer();
        sb.append("<script language='JavaScript'>\n");
        sb.append("window.alert('" + str + "');\n");
        sb.append("</script>\n");
        String result=sb.toString();                     //modify by zhulin 20040826
        sb=null;
        return result;
    }

    /**
     * JavaScript 关闭当前窗口
     * @return
     */
    public static String close() {
        StringBuffer sb = new StringBuffer();
        sb.append("<script language='JavaScript'>\n");
        sb.append("window.close();\n");
        sb.append("</script>\n");
        String result=sb.toString();                         //modify by zhulin 20040826
        sb=null;
        return result;
    }
    public static void alertOnly(String str, HttpServletRequest request,
			HttpServletResponse response) {
		StringBuffer sb = new StringBuffer(1024);
		try {
			sb.append("<html>\n");
			sb.append("<head>\n");
			sb.append("<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>\n");
			sb.append("<title> New Document</title>\n");
			sb.append("</head>\n");
			sb.append("<script language='JavaScript'>\n");
			sb.append("window.alert('" + str + "');\n");
			sb.append("</script>\n");
			sb.append("<body>\n");
			sb.append("</body>\n");
			sb.append("</html>\n");
			PrintWriter out = response.getWriter();
			out.print(sb.toString());
			out.close();
		} catch (IOException e) {
			e.printStackTrace(System.out);
		} finally {
			sb = null;
		}
	}
    /**
	 * JavaScript 把开启的窗口刷新后，关闭本窗口
	 */
    public static String openerReloadClose() {
        StringBuffer sb = new StringBuffer(1024);
        sb.append("<html>\n");
        sb.append("<head>\n");
        sb.append("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>\n");
        sb.append("<title> New Document</title>\n");
        sb.append("</head>\n");
        sb.append("<script language='JavaScript'>\n");
        sb.append("window.opener.location.reload();\n");
        sb.append("window.close();\n");
        sb.append("</script>\n");
        sb.append("<body>\n");
        sb.append("</body>\n");
        sb.append("</html>\n");
        String s = sb.toString();
        sb = null;
        return s;
    }

    /**
     * 得到颜色。用于表格分颜色显示
     * @param i
     * @return
     */
    public static String getBgColor(int i) {
        return i % 2 != 0 ? "#F6F6F6" : "";
    }

    /**
     * 取得action。用于表格的onmouseouver和onmouseout
     * @param i
     * @return
     */
    public static String getAction(int i) {
        return i % 2 != 0 ? "1" : "2";
    }

    /**
     * 从指定的集合中得到html格式的下拉框
     * @param v 集合
     * @param defaultValue 缺省选中的值
     * @param value 指定值的field
     * @param text 指定显示文本的field
     * @return 下拉框
     * @throws Exception
     */
    public static String getOptions(Vector v, String defaultValue, String value, String text) throws Exception {
        String result = "";
        if (v != null && v.capacity() > 0) {
            for (int i = 0; i < v.size(); i++) {
                String isSelect = "",vValue = "",vText = "";
                Object o = v.elementAt(i);
                Class aClass = o.getClass();
                Field fieldValue = aClass.getDeclaredField(value),fieldText = aClass.getDeclaredField(text);
                int modifiersValue = fieldValue.getModifiers();
                if (Modifier.isPublic(modifiersValue) && !Modifier.isStatic(modifiersValue) && !Modifier.isFinal(modifiersValue)) {
                    vValue = fieldValue.get(o).toString();
                    vText = fieldText.get(o).toString();
                } else {
                    Method methodValue = aClass.getMethod("get" + value.substring(0, 1).toUpperCase() + value.substring(1), null),
                            methodText = aClass.getMethod("get" + text.substring(0, 1).toUpperCase() + text.substring(1), null);
                    vValue = methodValue.invoke(o, null).toString();
                    vText = methodText.invoke(o, null).toString();
                }
                isSelect = vValue.equals(defaultValue) ? " selected" : "";
                result += "\n<option value='" + vValue + "'" + isSelect + ">" + vText + "</option>";
            }
        }
        return result;
    }

    /**
     * 从指定的集合中得到html格式的下拉框，<br>显示文本的格式为：[value]text
     * @param v 集合
     * @param defaultValue 缺省选中的值
     * @param value 指定值的field
     * @param text 指定显示文本的field
     * @return 下拉框
     * @throws Exception
     */
    public static String getOptionsWithCode(Vector v, String defaultValue, String value, String text) throws Exception {
        String result = "";
        if (v != null && v.capacity() > 0) {
            for (int i = 0; i < v.size(); i++) {
                String isSelect = "",vValue = "",vText = "";
                Object o = v.elementAt(i);
                Class aClass = o.getClass();
                Field fieldValue = aClass.getDeclaredField(value),fieldText = aClass.getDeclaredField(text);
                int modifiersValue = fieldValue.getModifiers();
                if (Modifier.isPublic(modifiersValue) && !Modifier.isStatic(modifiersValue) && !Modifier.isFinal(modifiersValue)) {
                    vValue = fieldValue.get(o).toString();
                    vText = fieldText.get(o).toString();
                } else {
                    Method methodValue = aClass.getMethod("get" + value.substring(0, 1).toUpperCase() + value.substring(1), null),
                            methodText = aClass.getMethod("get" + text.substring(0, 1).toUpperCase() + text.substring(1), null);
                    vValue = methodValue.invoke(o, null).toString();
                    vText = methodText.invoke(o, null).toString();
                }
                isSelect = vValue.equals(defaultValue) ? " selected" : "";
                result += "\n<option value='" + vValue + "'" + isSelect + ">[" + vValue + "]" + vText + "</option>";
            }
        }
        return result;
    }

    /**
     * 从指定的集合中得到html格式的下拉框
     * @param v 集合
     * @param defaultValue 缺省选中的值
     * @param value 指定值的field
     * @param text 指定显示文本的field
     * @return 下拉框
     * @throws Exception
     */
    public static String getOptions(Vector v, int defaultValue, String value, String text) throws Exception {
        String result = "";
        if (v != null && v.capacity() > 0) {
            for (int i = 0; i < v.size(); i++) {
                String isSelect = "",vValue = "",vText = "";
                Object o = v.elementAt(i);
                Class aClass = o.getClass();
                Field fieldValue = aClass.getDeclaredField(value),fieldText = aClass.getDeclaredField(text);
                int modifiersValue = fieldValue.getModifiers();
                if (Modifier.isPublic(modifiersValue) && !Modifier.isStatic(modifiersValue) && !Modifier.isFinal(modifiersValue)) {
                    vValue = fieldValue.getInt(o) + "";
                    vText = fieldText.get(o).toString();
                } else {
                    Method methodValue = aClass.getMethod("get" + value.substring(0, 1).toUpperCase() + value.substring(1), null),
                            methodText = aClass.getMethod("get" + text.substring(0, 1).toUpperCase() + text.substring(1), null);
                    vValue = methodValue.invoke(o, null).toString();
                    vText = methodText.invoke(o, null).toString();
                }
                isSelect = (defaultValue + "").equals(vValue) ? " selected" : "";
                result += "\n<option value='" + vValue + "'" + isSelect + ">" + vText + "</option>";
            }
        }
        return result;
    }

    /**
     * 把一个对象中的非static非final的值转到hashmap中<br>
     * 其中，hashmap的key为object中的field name，value为field的value
     * @param object 要转的对象
     * @return
     */
    public static HashMap getHashMap(Object object) {
        HashMap map = new HashMap();
        if (object != null) {
            Class aClass = object.getClass();
            Field[] declaredFields = aClass.getDeclaredFields();
            for (int i = 0; i < declaredFields.length; i++) {
                Field declaredField = declaredFields[i];
                String fieldName = declaredField.getName();
                int modifier = declaredField.getModifiers();
                if (Modifier.isPrivate(modifier) && !Modifier.isStatic(modifier) && !Modifier.isFinal(modifier)) {
                    String methodName;
                    String s = fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
                    if (declaredField.getType().equals(Boolean.TYPE)) {
                        methodName = "is" + s;
                    } else {
                        methodName = "get" + s;
                    }
                    Method method = null;
                    try {
                        method = aClass.getMethod(methodName, null);
                        map.put(fieldName, method.invoke(object, null));
                    } catch (Exception e) {
                    }
                }
            }
        }
        return map;
    }

}
